<template>
  <div class="components-container">
    <!-- <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.NameLike" placeholder="输入名称"></el-input>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">类别</label>
        <div class="layui-input-inline">
          <el-select v-model="selectData.TypeEquals" placeholder="请选择类别">
            <el-option v-for="item in UnttypeOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">统计地址</label>
        <div class="layui-input-inline">
          <el-cascader :options="UntyuseroupOptions" v-model="carryArea" filterable :show-all-levels="false" change-on-select>
          </el-cascader>
        </div>
      </div>
      <el-button type="primary" @click="btnSearch" :disabled="downloadLoading" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button :disabled="this.$store.state.isloading || downloadLoading" @click="btnRepeat">重置</el-button>
    </div> -->
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :disabled="$store.state.isloading || downloadLoading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :height="height" :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <!-- <dataTable :headList="headList" :dataList="dataList" :hiddenWarn="hiddenWarn" :clounmnames="clounmnames" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable> -->
    <printmodal ref="printPdf"></printmodal>
    <!-- 操作弹窗 -->
    <main-model ref="dialog" @refreshData="getData"></main-model>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
    margin-left: 0;
}
.btn {
    text-align: center;
}
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import printmodal from "@/components/Pdf/Print";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { PRINT } from "@/components/Pdf/PDF.js";
import mainModel from "./leaveMain";
const EXPORT = "打印";
export default {
    name: "unitManage",
    mixins: [manage],
    data() {
        return {
            selectData: {},
            downloadLoading: false,
            OutDataExcel: [],
            message: null,
            height: "620",
            sweetModalWidth: 80,
            sweetModalMaxWidth: 1000,
            hiddenColumn: true,
            carryArea: [],
            UnttypeOptions: [],
            UntyuseroupOptions: []
        };
    },
    methods: {
        exportExcel() {
            var startTime;
            var endTime;
            if (this.selectData.CdhactualdateGreaterAndEquals) {
                startTime = this.selectData.CdhactualdateGreaterAndEquals.toLocaleDateString();
            } else {
                startTime = "空";
            }
            if (this.selectData.CdhactualdateLessAndEquals) {
                endTime = this.selectData.CdhactualdateLessAndEquals.toLocaleDateString();
            } else {
                endTime = "空";
            }
            var header = "单位统计表" + "(" + startTime + "--" + endTime + ")";
            if (this.dataList.length === 0) {
                this.$message.error("无导出数据！");
                return;
            }
            this.downloadLoading = true;
            require.ensure([], () => {
                const {
                    export_json_to_excel
                } = require("@/vendor/Export2Excel");
                export_json_to_excel(this.headList, this.OutDataExcel, header);
                this.downloadLoading = false;
            });
        },
        //功能操作
        operate(order) {
            this.order = order;
            switch (this.order) {
                // case EXPORT:
                //   this.$refs.printPdf.report(PRINT.PDFDRIVERS,this.getDataC());
                //   break;
                case "修改":
                    this.$refs.dialog.open(this.order, this.currentRow.ODYID);
                    break;
                case "详情":
                    this.$refs.dialog.open("详情", this.currentRow.ODYID);
                    break;
                case "删除":
                    this.delete();
                    break;
                case "申请":
                    this.$refs.dialog.open("申请");
                    break;
                case "提交":
                    this.$refs.dialog.open("提交", this.currentRow.ODYID);
                    break;
                case "初审":
                    this.$refs.dialog.open("初审", this.currentRow.ODYID);
                    break;
                case "复审":
                    this.$refs.dialog.open("复审", this.currentRow.ODYID);
                    break;
                case "审批":
                    this.$refs.dialog.open("审批", this.currentRow.ODYID);
                    break;
                case "取消审批":
                    this.noshenpi();
                    break;
                case "备案":
                    this.beian();
                    break;
                default:
            }
        },
        //取消审批
        noshenpi(){
          let data = {
                ODYID: this.currentRow.ODYID
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().OnDuty.Back,
                res => {
                    this.$message({
                        type: "success",
                        message: "取消审批成功!"
                    });
                    this.getData();
                }
            );
        },
        //备案
        beian() {
            let data = {
                ODYID: this.currentRow.ODYID
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().OnDuty.Forward,
                res => {
                    this.$message({
                        type: "success",
                        message: "登记成功!"
                    });
                    this.getData();
                }
            );
        },

        //删除
        delete() {
            this.$confirm("确认是否删除该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        ODYID: this.currentRow.ODYID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().OnDuty.Delete,
                        res => {
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        getColumns() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Column.GetOnDutyColumns,
                res => {
                    this.headList = res.data.content;
                }
            );
        },
        //  getDataC(){
        //     let Data = JSON.parse(JSON.stringify(this.selectData));
        //     if(Data.RegiskeypointEquals === null || Data.RegiskeypointEquals === undefined) Data.RegiskeypointEquals = 'A';
        //      Data.CdhactualdateGreaterAndEquals = formatDate(
        //       Data.CdhactualdateGreaterAndEquals,
        //       "yyyyMMdd"
        //     );
        //     Data.CdhactualdateLessAndEquals = formatDate(
        //       Data.CdhactualdateLessAndEquals,
        //       "yyyyMMdd"
        //     );
        //     let data = {
        //       PageIndex: 1,
        //       PageSize: 100,
        //       OrderBy: this.pageOrder.orderType,
        //       OrderByType: this.pageOrder.orderSort,
        //       Data: Data
        //     };
        //     return data;
        //   },
        getData() {
            let data = {
                 PageIndex: this.pageOrder.currentPage,
                PageSize: this.pageOrder.pageSize,
                OrderBy: this.pageOrder.orderType,
                OrderByType: this.pageOrder.orderSort,
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().OnDuty.Query,
                res => {
                    // this.hiddenColumnInfo = true;
                    this.dataList = res.data.content.OutData;
                    this.OutDataExcel = res.data.content.OutData;
                    this.pageOrder.totalNum = res.data.content.RecordCount;
                }
            );
        },
        // 流程前进  ODYID : Id
        Forward() {
            let data = {
                ODYID: this.currentRow.ODYID
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().OnDuty.Forward,
                res => {
                    this.$message.success("成功！");
                    // this.headList = res.data.content;
                }
            );
        },
        // 流程后退
        Back() {
            let data = {
                ODYID: this.currentRow.ODYID
            };
            apiBase.DoService(data, apiBase.getApiAdress().OnDuty.Back, res => {
                this.$message.success("成功！");
                // this.headList = res.data.content;
            });
        },

        // dataRepeat(){},
        btnRepeat() {
            this.selectData = {};
            this.getData();
        },
        btnShow(btn) {
            if (this.currentRow) {
                var status = this.currentRow.ODYSTATUS;
            }
            switch (btn) {
                case "申请":
                    return true;
                    break;
                case "详情":
                    return true;
                    break;
                case "提交":
                case "修改":
                case "删除":
                    if (status === "A") return true;
                    break;
                case "初审":
                    if (status === "B") return true;
                    break;
                case "复审":
                    if (status === "C") return true;
                    break;
                case "审批":
                    if (status === "D") return true;
                    break;
                case "备案":
                case "取消审批":
                    if (status === "E") return true;
                    break;
                default:
                    return false;
            }
        }
    },
    mounted() {},
    components: {
        dataTable,
        mainModel,
        printmodal
    },

    created() {
        this.getColumns();
        this.getData();
        var data = {
            type: "单位类别"
        };
        apiBase.DoService(data, apiBase.getApiAdress().Code.GetType, res => {
            let cardata = res.data.content;
            this.UnttypeOptions = cardata.map(item => ({
                value: item.CodeValue,
                label: item.CodeName
            }));
        });
        apiBase.DoService(
            {},
            apiBase.getApiAdress().Code.GetAddressMap,
            res => {
                let cardata = res.data.content;
                this.UntyuseroupOptions = cardata.map(item => ({
                    value: item.ADDID,
                    label: item.ADDNAME,
                    ADDLEVEL: item.ADDLEVEL,
                    ADDTOPID: item.ADDTOPID,
                    children: item.Children.map(itemStr => ({
                        value: itemStr.ADDID,
                        label: itemStr.ADDNAME,
                        ADDLEVEL: itemStr.ADDLEVEL,
                        ADDTOPID: itemStr.ADDTOPID
                    }))
                }));
            }
        );
    }
};
</script>